package com.emm.yixun.website.utils;
import java.security.InvalidParameterException;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.beanutils.PropertyUtils;

import com.emm.yixun.common.model.dto.EnumClass;
public class EnumUtils {

	public static <T> List<EnumClass> buildEnumJson(Class<T> clazz) {
		if (!clazz.isEnum()) {
			throw new InvalidParameterException();
		}
		try {
			T[] enumConstants = clazz.getEnumConstants();
			List<EnumClass> array = new ArrayList<EnumClass>();
			for (T ec : enumConstants) {
				Object key = PropertyUtils.getProperty(ec, "no");
				Object value = PropertyUtils.getProperty(ec, "des");
				if (key != null) {
					EnumClass ecs = new EnumClass(key.toString(), value.toString());
					array.add(ecs);
				}
			}
			return array;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
	public static List<EnumClass> getEnumJson(String classPath){
		try {
			Class<?> cls=Class.forName(classPath);
			return buildEnumJson(cls);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
		
	}
}